﻿@model HomeControllerModel.Index
<div class="row">
    <div class="span2">
        asdfasf
    </div>
    <div class="span10">
        <div class="row">
            <div class="span5">
                <div class="gallery">
                    <div class="picture">
                        <a href="http://img12.360buyimg.com/n0/1587/69fbd371-c9bd-406b-98cc-fe195b9a3a3c.jpg"
                            class="item-gallery" rel='gallery' title="尼康（Nikon） D3100 单反套机（AF-S DX 18-55mm f/3.5-5.6G VR尼克尔镜头）黑色">
                            <img src="http://img12.360buyimg.com/n1/1587/69fbd371-c9bd-406b-98cc-fe195b9a3a3c.jpg"
                                alt="" />
                        </a>
                        <div class="zoom-icon">
                        </div>
                    </div>
                    <div id="item-gallery-thumb">
                        <div class="slides-container">
                            <div class="thumb clearfix">
                                <a class="zoomThumbActive" href='javascript:void(0);' rel="{gallery: 'gallery', smallimage: 'http://img12.360buyimg.com/n1/1587/69fbd371-c9bd-406b-98cc-fe195b9a3a3c.jpg',largeimage: 'http://img12.360buyimg.com/n0/1587/69fbd371-c9bd-406b-98cc-fe195b9a3a3c.jpg'}">
                                    <img src="http://img12.360buyimg.com/n5/1587/69fbd371-c9bd-406b-98cc-fe195b9a3a3c.jpg"
                                        width="50" height="50" alt="尼康（Nikon） D3100 单反套机（AF-S DX 18-55mm f/3.5-5.6G VR尼克尔镜头）黑色" /></a>
                                <a href='javascript:void(0);' rel="{gallery: 'gallery', smallimage: 'http://img12.360buyimg.com/n1/3538/023399f8-376d-45af-b2d3-57c464952563.jpg',largeimage: 'http://img12.360buyimg.com/n0/3538/023399f8-376d-45af-b2d3-57c464952563.jpg'}">
                                    <img onerror="this.src='http://www.360buy.com/images/none/none_50.gif'" src="http://img12.360buyimg.com/n5/3538/023399f8-376d-45af-b2d3-57c464952563.jpg"
                                        width="50" height="50" alt="尼康（Nikon） D3100 单反套机（AF-S DX 18-55mm f/3.5-5.6G VR尼克尔镜头）黑色" /></a>
                                <a href='javascript:void(0);' rel="{gallery: 'gallery', smallimage: 'http://img12.360buyimg.com/n1/1587/69fbd371-c9bd-406b-98cc-fe195b9a3a3c.jpg',largeimage: 'http://img12.360buyimg.com/n0/1587/69fbd371-c9bd-406b-98cc-fe195b9a3a3c.jpg'}">
                                    <img src="http://img12.360buyimg.com/n5/1587/69fbd371-c9bd-406b-98cc-fe195b9a3a3c.jpg"
                                        width="50" height="50" alt="尼康（Nikon） D3100 单反套机（AF-S DX 18-55mm f/3.5-5.6G VR尼克尔镜头）黑色" /></a>
                                <a href='javascript:void(0);' rel="{gallery: 'gallery', smallimage: 'http://img12.360buyimg.com/n1/3538/023399f8-376d-45af-b2d3-57c464952563.jpg',largeimage: 'http://img12.360buyimg.com/n0/3538/023399f8-376d-45af-b2d3-57c464952563.jpg'}">
                                    <img onerror="this.src='http://www.360buy.com/images/none/none_50.gif'" src="http://img12.360buyimg.com/n5/3538/023399f8-376d-45af-b2d3-57c464952563.jpg"
                                        width="50" height="50" alt="尼康（Nikon） D3100 单反套机（AF-S DX 18-55mm f/3.5-5.6G VR尼克尔镜头）黑色" /></a>
                                <a href='javascript:void(0);' rel="{gallery: 'gallery', smallimage: 'http://img12.360buyimg.com/n1/1587/69fbd371-c9bd-406b-98cc-fe195b9a3a3c.jpg',largeimage: 'http://img12.360buyimg.com/n0/1587/69fbd371-c9bd-406b-98cc-fe195b9a3a3c.jpg'}">
                                    <img src="http://img12.360buyimg.com/n5/1587/69fbd371-c9bd-406b-98cc-fe195b9a3a3c.jpg"
                                        width="50" height="50" alt="尼康（Nikon） D3100 单反套机（AF-S DX 18-55mm f/3.5-5.6G VR尼克尔镜头）黑色" /></a>
                            </div>
                            <div class="thumb clearfix">
                                <a class="zoomThumbActive" href='javascript:void(0);' rel="{gallery: 'gallery', smallimage: 'http://img12.360buyimg.com/n1/1587/69fbd371-c9bd-406b-98cc-fe195b9a3a3c.jpg',largeimage: 'http://img12.360buyimg.com/n0/1587/69fbd371-c9bd-406b-98cc-fe195b9a3a3c.jpg'}">
                                    <img src="http://img12.360buyimg.com/n5/1587/69fbd371-c9bd-406b-98cc-fe195b9a3a3c.jpg"
                                        width="50" height="50" alt="尼康（Nikon） D3100 单反套机（AF-S DX 18-55mm f/3.5-5.6G VR尼克尔镜头）黑色" /></a>
                                <a href='javascript:void(0);' rel="{gallery: 'gallery', smallimage: 'http://img12.360buyimg.com/n1/3538/023399f8-376d-45af-b2d3-57c464952563.jpg',largeimage: 'http://img12.360buyimg.com/n0/3538/023399f8-376d-45af-b2d3-57c464952563.jpg'}">
                                    <img onerror="this.src='http://www.360buy.com/images/none/none_50.gif'" src="http://img12.360buyimg.com/n5/3538/023399f8-376d-45af-b2d3-57c464952563.jpg"
                                        width="50" height="50" alt="尼康（Nikon） D3100 单反套机（AF-S DX 18-55mm f/3.5-5.6G VR尼克尔镜头）黑色" /></a>
                                <a href='javascript:void(0);' rel="{gallery: 'gallery', smallimage: 'http://img12.360buyimg.com/n1/1587/69fbd371-c9bd-406b-98cc-fe195b9a3a3c.jpg',largeimage: 'http://img12.360buyimg.com/n0/1587/69fbd371-c9bd-406b-98cc-fe195b9a3a3c.jpg'}">
                                    <img src="http://img12.360buyimg.com/n5/1587/69fbd371-c9bd-406b-98cc-fe195b9a3a3c.jpg"
                                        width="50" height="50" alt="尼康（Nikon） D3100 单反套机（AF-S DX 18-55mm f/3.5-5.6G VR尼克尔镜头）黑色" /></a>
                                <a href='javascript:void(0);' rel="{gallery: 'gallery', smallimage: 'http://img12.360buyimg.com/n1/3538/023399f8-376d-45af-b2d3-57c464952563.jpg',largeimage: 'http://img12.360buyimg.com/n0/3538/023399f8-376d-45af-b2d3-57c464952563.jpg'}">
                                    <img onerror="this.src='http://www.360buy.com/images/none/none_50.gif'" src="http://img12.360buyimg.com/n5/3538/023399f8-376d-45af-b2d3-57c464952563.jpg"
                                        width="50" height="50" alt="尼康（Nikon） D3100 单反套机（AF-S DX 18-55mm f/3.5-5.6G VR尼克尔镜头）黑色" /></a>
                                <a href='javascript:void(0);' rel="{gallery: 'gallery', smallimage: 'http://img12.360buyimg.com/n1/1587/69fbd371-c9bd-406b-98cc-fe195b9a3a3c.jpg',largeimage: 'http://img12.360buyimg.com/n0/1587/69fbd371-c9bd-406b-98cc-fe195b9a3a3c.jpg'}">
                                    <img src="http://img12.360buyimg.com/n5/1587/69fbd371-c9bd-406b-98cc-fe195b9a3a3c.jpg"
                                        width="50" height="50" alt="尼康（Nikon） D3100 单反套机（AF-S DX 18-55mm f/3.5-5.6G VR尼克尔镜头）黑色" /></a>
                            </div>
                        </div>
                    </div>
                    <div class="action">
                        <div class="placeholder">
                            asdfasf</div>
                    </div>
                </div>
            </div>
            <div class="span5">
                <div class="property">
                    <h3>
                        afasdf</h3>
                    <div class="item-meta">
                        <p>
                            价格：<span class="item-price">@Model.Product.UnitPrice</span></p>
                    </div>
                    <div class="item-attribute">
                        <dl class="dl-horizontal">
                            @if (Model.Product.ProductSaleAttributesInfo != null)
                            {
                                foreach (var o in Model.Product.ProductSaleAttributesInfo)
                                {
                                <dt>@(o.Text)：</dt>
                                <dd>
                                    <ul class="unstyled inline">
                                        @foreach (var v in o.Values)
                                        {
                                            if (Model.Product.Dimension == ProductDimension.One)
                                            {
                                            <li data-namecode="@(o.Code)" data-valuecode="@(v.Key)" class="@(Model.SelectedAttributes.Contains(v.Key) ? "item-selected" : string.Empty)">
                                                <a href="javascript:void(0);"><span>@v.Value</span> </a>
                                                @if (Model.SelectedAttributes.Contains(v.Key))
                                                {
                                                    <i>已选中</i>
                                                }
                                            </li>
                                            }
                                            else
                                            {
                                            <li data-namecode="@(o.Code)" data-valuecode="@(v.Key)" ><a href="javascript:void(0);">
                                                <span>@v.Value</span> </a></li>
                                            }
                                        }
                                    </ul>
                                </dd>
                                }
                                <dt>数 量：</dt><dd>
                                    <div class="input-prepend input-append">
                                        <span class="add-on"><a href="javascript:void(0);"><i class="icon-minus"></i></a>
                                        </span>
                                        <input id="item-quantity" class="input-mini" type="text" title="请输入购买量" maxlength="3"
                                            value="1" />
                                        <span class="add-on"><a href="javascript:void(0);"><i class="icon-plus"></i></a>
                                        </span><span class="add-on">(库存 <span id="item-stock" class="item-stock">@(Model.Product.ProductVariants.Sum(o => o.VariantQuantity))</span>件)</span>
                                    </div>
                                </dd>
                            }
                        </dl>
                        <ul class="unstyled item-action">
                            <li class="item-action-buy"><a href="javascript:void(0);"></a></li>
                            <li class="item-action-add"><a href="javascript:void(0);"></a></li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@section js
{
    @Url.Sk().StaticJs("jquery.slides.min")
    @Url.Sk().StaticJs("jquery.jqzoom.pack")
    <script src="/@(Model.Product.Id).js" type="text/javascript"></script>
    <script type="text/javascript">
        var item = itemInfo || {};
        $(function () {
            $(".item-attribute dl dd ul li").click(function () {
                var target = this;
                var price = item.Price;
                var quantity = item.Stock;

                if ($(target).hasClass("item-out-of-stock"))
                    return false;
                if ($(target).hasClass("item-selected")) {
                    $(".item-price").text(price);
                    $(".item-stock").text(quantity);

                    $(target).children("i").remove();
                    $(target).removeClass("item-selected");

                }
                else {
                    $(target).addClass("item-selected");
                    $(target).append("<i>已选中</i>");

                    var namecode = $(target).attr("data-namecode");
                    var valuecode = $(target).attr("data-valuecode");

                    var other = $(target).parent().children().not(target);
                    $.each(other, function (i, n) {
                        $(n).children("i").remove();
                        $(n).removeClass("item-selected");
                    });
                    var subAttrs = $.Enumerable.From(item.VariantAttributes).Where(function (o) {
                        return o.Key == valuecode;
                    }).FirstOrDefault();
                    if (subAttrs != undefined && subAttrs != null) {
                        subAttrs = subAttrs.Value;
                        var list = $(".item-attribute li[data-namecode!='" + namecode + "']");
                        $.each(list, function (i, n) {
                            var code = $(n).attr("data-valuecode");
                            if ($.inArray(code, subAttrs) == -1) {
                                $(n).addClass("item-out-of-stock");
                            }
                            else {
                                $(n).removeClass("item-out-of-stock");
                            }
                        });
                    }
                    //更新价格 库存
                    if (item.Dimension == 1) {
                        var x = $.Enumerable.From(item.Variants).Where(function (o) {
                            return o.Code == valuecode;
                        }).FirstOrDefault();
                        if (x != undefined && x != null) {
                            price = x.Price;
                            quantity = x.Quantity;
                        }
                        //console.log(x);
                    }
                    else if (item.Dimension == 2) {
                        var selecteds = $(".item-attribute li[class='item-selected']");
                        if (selecteds.length != 2) {
                            return false;
                        } else {
                            var tempId = [];
                            $.each(selecteds, function (i, n) {
                                var code = $(n).attr("data-valuecode");
                                tempId.push(code);
                            });
                            var z = tempId.toString();
                            var y = $.Enumerable.From(item.Variants).Where(function (o) {
                                return o.Code == z;
                            }).FirstOrDefault();
                            //console.log(y);
                            if (y != undefined && y != null) {
                                price = y.Price;
                                quantity = y.Quantity;
                            }
                        }
                    }
                    $(".item-price").text(price);
                    $(".item-stock").text(quantity);
                }
                return false;
            });

            $(".item-action-add a").click(function () {
//                if (Sk.CurrentUser.IsAuthenticated == false) {
//                    Sk.Passport.Fun.login();
//                    return false;
//                }
                alert(0);
                var stock = 0;
                var id = item.Id;
                var guid = item.Variants[0].Id;
                var quantity = parseInt($("#item-quantity").val()) || 1;
                if (item.Dimension == 0) {
                    stock = item.Variants[0].Quantity;
                }
                if (item.Dimension == 1) {
                    var valuecode = $(".item-attribute li[class='item-selected']").first().attr("data-valuecode");
                    var x = $.Enumerable.From(item.Variants).Where(function (o) {
                        return o.Code == valuecode;
                    }).FirstOrDefault();
                    if (x != undefined && x != null) {
                        stock = x.Quantity;
                    }
                }
                if (item.Dimension == 2) {
                    var selecteds = $(".item-attribute li[class='item-selected']");
                    if (selecteds.length != 2) {
                        $(".item-attribute").addClass("item-attention");
                        return false;
                    } else {
                        var tempId = [];
                        $.each(selecteds, function (i, n) {
                            var code = $(n).attr("data-valuecode");
                            tempId.push(code);
                        });
                        var temp = $.Enumerable.From(item.Variants).Where(function (o) {
                            return o.Code == tempId.toString();
                        }).FirstOrDefault();
                        if (temp != undefined && temp != null) {
                            guid = temp.Id;
                            stock = temp.Quantity;
                        }
                    }
                }
                if (quantity > stock) {
                    alert('数量不对');
                    return false;
                }
                //debugger;
                var url = $.format('{0}/add/{1}?id={2}&qty={3}&callback=?', Sk.Domain.Cart, id, guid, quantity);
                $.getJSON(url, function (result) {
                    if (result.Status == true) {
                        Sk.Cart.RenderMiniCart();
                    }
                });
                return false;
            });

            $(".item-tabs .trigger").click(function (e) {
                var sec = $(e.target).parent();
                if (!sec.hasClass("active")) {
                    $("li.active").removeClass("active");
                    sec.addClass("active");
                }
            });
        });
        
       
    </script>
    <script type="text/javascript">
        $(function () {
            $('.item-gallery').jqzoom();
            $('#item-gallery-thumb').slides({
                generateNextPrev: true, generatePagination: false
            });
        }); </script>
}
@section css
{
    @Url.Sk().StaticCss("jquery.jqzoom")
    <style type="text/css">
        
    </style>
}
